#!/usr/bin/env sh
##
## This script launches the heritrix crawler and keeps the process in foreground
##
## Optional environment variables
##
## JAVA_HOME        Point at a JDK install to use.
## 
## HERITRIX_HOME    Pointer to your heritrix install.  If not present, we 
##                  make an educated guess based of position relative to this
##                  script.
##
## JAVA_OPTS        Java runtime options.
##
## FOREGROUND       Set to any value -- e.g. 'true' -- if you want to run 
##                  heritrix in foreground (Used by build system when it runs
##                  selftest to see if completed successfully or not)..
##

# Resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done
PRGDIR=`dirname "$PRG"`

# Set HERITRIX_HOME.
if [ -z "$HERITRIX_HOME" ]
then
    HERITRIX_HOME=`cd "$PRGDIR/.." ; pwd`
fi

FOREGROUND='true' /bin/sh $HERITRIX_HOME/bin/heritrix $@
